<?php
/**
 * Created by PhpStorm.
 * User: Administrator--Reer
 * Date: 2019/9/9 0009
 * Time: 17:09
 */

namespace app\store\controller;

use app\common\bean\GlobalBean;
use app\common\bean\StoreUserBean;
use app\common\enum\StoreUserIsUpdatePwEnum;
use app\common\exception\MyException;
use app\common\manage\StoreUserManage;
use app\common\utils\ExitJsonUtil;
use think\App;
use think\Controller;

class NoCheckPermission extends Controller
{
    /*
     * 不需验证操作权限、但是需要登录
     */
    /**
     * NoCheckPermission constructor.
     * @param App|null $app
     * @throws \Exception
     */
    public function __construct(App $app = null) {
        if(!session(GlobalBean::$storeId)){
            MyException::throwMyException(GlobalBean::$goLogin);
        }
        parent::__construct($app);
    }

    /** 修改个人信息
     * @return mixed
     * @throws \Exception
     */
    public function editSelfMessage(){
        $storeUserBean = new StoreUserBean();
        $storeUserBean->setData(request()->post());
        $storeUserBean->setId(session(GlobalBean::$storeUserId));
        $storeUserBean->setStoreId(session(GlobalBean::$storeId));
        $storeUserManage = StoreUserManage::getInstance();
        if(request()->isAjax() && request()->isPost()){
            $storeUserBean->setIsUpdatePw(StoreUserIsUpdatePwEnum::NO);
            $storeUserBean->setStoreRoleId(session(GlobalBean::$storeRoleId));
            $result = $storeUserManage->edit($storeUserBean);
            ExitJsonUtil::getInstance()->exitData($result);
        }
        $storeUserBean = $storeUserManage->getInfo($storeUserBean);
        $this->assign("self",true);
        $this->assign("storeUser",$storeUserBean->getData());
        return $this->fetch('store_user/edit_user');
    }

}